<%@ include file="IsProff.jsp"%>
<%@ page import="database.*,  java.sql.*" %>
<%!
public void check(String [] arr)
{
	for(int i=0;i<arr.length;i++)
	{
		while(arr[i] != null && arr[i].indexOf("\n") != -1)
		{
			arr[i] = arr[i].substring(0,arr[i].indexOf("\n")-1) + "<br/>" + arr[i].substring(arr[i].indexOf("\n")+1,arr[i].length());
		}
	}
}
%>
<%
DBCon db = new DBCon();
String control = db.getControlValue("project_update");
            
if(control.equals("true"))
{
String profId = (String) session.getAttribute("ProfID");

if(profId == null)
	response.sendRedirect("error.jsp");
else
{

String [] proj = new String[10];




			String pid = request.getParameter("pId");
			
			ResultSet rs1 = null;
			rs1 = db.getProject("where id="+pid);
		if(rs1.next())
			{
				proj[0] = rs1.getString("Title");
				proj[1] = rs1.getString("description");
				proj[2] = rs1.getString("Project_Objectives");
				proj[3] = rs1.getString("Required_Background");
				proj[4] = rs1.getString("Tools_Needed");
				proj[5] = rs1.getString("Difficulty_Level");
				proj[6] = rs1.getString("Project_Type");
				proj[7] = rs1.getString("Project_Keywords");
				proj[8] = rs1.getString("Expected_Results");
				proj[9] = rs1.getString("Additional_Comments");
			}
			
			check(proj);

			out.println("<script type='text/javascript'>");
			out.println("var dproj = new Array();"); 
			out.println("var pid= '"+pid+"';");
			out.println("dproj[0] = '"+ proj[0]+"';");
			out.println("dproj[1] = '"+ proj[1]+"';");
			out.println("dproj[2] = '"+ proj[2]+"';");
			out.println("dproj[3] = '"+ proj[3]+"';");
			out.println("dproj[4] = '"+ proj[4]+"';");
			out.println("dproj[5] = '"+ proj[5]+"';");
			out.println("dproj[6] = '"+ proj[6]+"';");
			out.println("dproj[7] = '"+ proj[7]+"';");
			out.println("dproj[8] = '"+ proj[8]+"';");
			out.println("dproj[9] = '"+ proj[9]+"';");
			out.println("</script>");
			

		

%>
<html>
<head>
<style>

    

.free {
	margin-right:0px;
	color: white;
	background-color: #877065;
	font-size: 8pt;
	font-weight: bold;
	text-align: center;
	border-bottom: solid 1px #aaaaaa;
	border-right: solid 1px #aaaaaa;
	border-left: solid 1px #aaaaaa;
	border-top: solid 1px #aaaaaa;
	cursor:pointer;
	width: 90px; 
	height: 35px;	
}


.choosen {
	margin-right:0px;
	color: black;
	background-color: #eeeeee;
	font-weight: bold;
	font-size: 8pt;
	border-bottom: none;
	border-left:  solid 1px #877065;
	border-top: solid 1px #877065;
	border-right:  solid 1px #877065;
	text-align:center;
	width: 90px; 
	height: 35px;
}

.tabsbody {
	font-size: 13pt;
	background-color: #eeeeee;
	border-bottom: solid 1px #4f75a6;
	border-left:  solid 1px #4f75a6;
	border-right:  solid 1px #4f75a6;
}
.Btable {
	border-left:solid 1px black;
	border-right: solid 1px black;
	border-top:solid 1px black;
	border-bottom: solid 1px black;
}

.mainDiv{
	overflow: auto;
	}


</style>


</head>

<body onload="onLoadDo()">
<script language="javascript" type="text/javascript">
var newProject = new Array("","","","","","","","","","");
var previousType = "description";
var firstS = true;
var firstF = true;
var firstC = true;
function show1(type)
{
	var pre = eval("document.addProject."+previousType);
	pre.value = document.getElementById("txta").value;
	document.getElementById("txta").value = eval("document.addProject."+type+".value");
	document.getElementById(previousType).className = "free";
	document.getElementById(type).className = "choosen";
	previousType = type;
	
}

function openPreviewWindow(x,y,page)
{
	textFill();
	var maxX=screen.width; 
	var maxY= screen.height;
	var wX = window.width;
	var wY = window.height;
	var wdth;
	var heght;
	if(x == 0)
	{
		wdth = maxX - (maxX/4);
		heght = maxY -(maxY/4);
	}
	else
	{
		wdth = x;
		heght = y;
	}	
	window.open(page+".jsp",page,"height="+heght+",width="+wdth+",scrollbar=yes").moveTo((maxX/2)-(wdth/2),(maxY/2)-(heght/2));
	
}
function textFill()
{
	var pre = eval("document.addProject."+previousType);
	pre.value = document.getElementById("txta").value;
}

function addDone()
{
	textFill();
	var div = document.getElementById("errorAdd");
	if(document.addProject.Title.value=="")
	{
		div.innerHTML = "<font style='background-color: white; font-size:12pt' face='Arial' color = 'red'>Your project details are not compelete, please check the title field!</font>";
		
		return false;
	}
	else if(document.addProject.description.value=="")
	{
		div.innerHTML = "<font style='background-color: white; font-size:12pt' face='Arial' color = 'red'>Your project details are not compelete, please check the description field!</font>";
		
		return false;
	}
	else if(document.addProject.project_objectives.value=="")
	{
		div.innerHTML = "<font style='background-color: white; font-size:12pt' face='Arial' color = 'red'>Your project details are not compelete, please check the project objectives field!</font>";
		
		return false;
	}
	else if(document.addProject.required_background.value=="")
	{
		div.innerHTML = "<font style='background-color: white; font-size:12pt' face='Arial' color = 'red'>Your project details are not compelete, please check the required background field!</font>";
		
		return false;
	}
	else if(document.addProject.tools_needed.value=="")
	{
		div.innerHTML = "<font style='background-color: white; font-size:12pt' face='Arial' color = 'red'>Your project details are not compelete, please check the tools needed field!</font>";
		
		return false;
	}
	else if(document.addProject.project_type.value=="")
	{
		div.innerHTML = "<font style='background-color: white; font-size:12pt' face='Arial' color = 'red'>Your project details are not compelete, please check the project type field!</font>";
		
		return false;
	}
	else if(document.addProject.project_keywords.value=="")
	{
		div.innerHTML = "<font style='background-color: white; font-size:12pt' face='Arial' color = 'red'>Your project details are not compelete, please check the project keywords field!</font>";
		
		return false;
	}
	else if(document.addProject.expected_results.value=="")
	{
		div.innerHTML = "<font style='background-color: white; font-size:12pt' face='Arial' color = 'red'>Your project details are not compelete, please check the expected result field!</font>";
		
		return false;
	}
		
		
	//onfocus="resetError()"
	return true;
}

function resetError()
{
	var div = document.getElementById("errorAdd");
	div.style.bgcolor = "white";
	div.innerHTML = "";
}

function onLoadDo()
{
	
	
	
	document.getElementById("title").value = dproj[0];
	document.getElementById("txta").value = dproj[1];
	document.addProject.pid.value = pid;
	document.addProject.description.value = dproj[1];
	document.addProject.project_objectives.value = dproj[2];
	document.addProject.required_background.value = dproj[3];
	document.addProject.tools_needed.value = dproj[4];
	document.addProject.difficulty_level.value = dproj[5];
	document.addProject.project_type.value = dproj[6];
	document.addProject.project_keywords.value = dproj[7];
	document.addProject.expected_results.value = dproj[8];
	document.addProject.additional_comments.value = dproj[9];
	
	document.body.scroll = "yes";
	
}



function sendP(action)
{
    document.addProject.type.value = action;
    document.addProject.submit();
}  

</script>
<center>

<form onsubmit= "return addDone()" name= "addProject" method="POST" action="updateProjectA.jsp">

<center><table class="Btable" border="0" height= "50%" width="99%" cellspacing="0" cellpadding="0" >
<tr><td align="left" style="color: #000000; font-size: 12pt; padding: 0px" colspan="8"><b>Title:</b>&nbsp;&nbsp;&nbsp;<input style="width:90%; padding: 3px; font-size:12pt; color: #000000" type="text" name= "title" id= "title">
	</td>
</tr>
<tr>
	<td id="description" class="choosen" onclick="show1('description')">Description
	</td>
	<td id="project_objectives" class="free" onclick="show1('project_objectives')">Project<br>Objectives
	</td>
	<td id="required_background" class="free" onclick="show1('required_background')">Required<br>Background
	</td>
	<td id="tools_needed" class="free" onclick="show1('tools_needed')">Tools<br>Needed
	</td>
	<td id="difficulty_level" class="free" onclick="show1('difficulty_level')">Difficulity<br>Level
	</td>
	<td id="project_type" class="free" onclick="show1('project_type')">Project<br>Type
	</td>
	<td id="project_keywords" class="free" onclick="show1('project_keywords')">Project<br>Keywords
	</td>
	<td id="expected_results" class="free" onclick="show1('expected_results')">Expected<br>Results
	</td>
	<td id="additional_comments" class="free" onclick="show1('additional_comments')">Additional<br>Comments
	</td>
</tr>	

<tr height="100%" style=" padding: 0px">
	<td class="tabsbody" colspan="10">
		
                 <br><center><textarea id= "txta" onchange="textFill()" onfocus="textFill()" wrap="soft" style="font-size:12pt; width:98%; background-color: #eef3f7" ROWS="10"></textarea></center><br>
	</td>
</tr>
<tr>
	<td colspan="10">
		<input type="hidden" name="pid"/>
		<input type="hidden" name="description"/>
		<input type="hidden" name="project_objectives"/>
		<input type="hidden" name="required_background"/>
		<input type="hidden" name="tools_needed"/>
		<input type="hidden" name="difficulty_level"/>
		<input type="hidden" name="project_type"/>
		<input type="hidden" name="project_keywords"/>
		<input type="hidden" name="expected_results"/>
		<input type="hidden" name="additional_comments"/>
                 <input type="hidden" name="type"/>
		
		<center><INPUT TYPE="button" VALUE="Add Image" onclick="alert('Sorry, not available yet.');"/></center>
	</td>
</tr>
<tr>
	<td colspan="9">
		<center><input type="button" value ="Preview" onclick="openPreviewWindow(0,0,'preview')"/>&nbsp;&nbsp;&nbsp;<input type="button" value ="Save draft" onclick="sendP('uncompleted')"/>&nbsp;&nbsp;&nbsp;<input type="button" value ="Submit Project" onclick="sendP('pending')"/></center>
	</td>
</tr>
	 </table>
</form>
</center>
<div id="errorAdd"></div>

</body>
</html>
<%}

}else{%>
<br/><br/><center><h2> This service is not availabe now </h2></center>
<%}%>
